package hello;

import java.util.Arrays;

public class Case7 {
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 4, 5, 6, 7, 8};
        int[] arr2 = new int[3];
        arr2 = Arrays.copyOfRange(arr1, 0, 3);
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
        for (int x : arr1) {
            System.out.println(x);
        }
        System.out.println("分割");
        Arrays.sort(arr1);
        System.out.println(arr1[0]);

        String[] str = {"aa", "bb", "cc", "dd"};
        for (String ss : str) {
            System.out.println(ss);
        }
        Arrays.fill(str, 2, 3, "bb");
        for (String ss : str) {
            System.out.println(ss);
        }

        int ints[][] = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        reverse(ints);
        printArray(ints);
    }

    /**
     * 二维数组转置
     *
     * @param ints
     */
    public static void reverse(int ints[][]) {
        int count = 0;//统计总共循环次数
        for (int i = 0; i < ints.length - 1; i++) {
            for (int j = i + 1; j < ints[i].length; j++) {//列循环从：i+1开始，提高循环效率
                int temp = ints[i][j];
                ints[i][j] = ints[j][i];
                ints[j][i] = temp;
                count++;
            }
        }
        System.out.println(count);
    }

    public static void printArray(int ints[][]) {
        for (int i = 0; i < ints.length; i++) {
            for (int j = 0; j < ints[i].length; j++) {
                System.out.print(ints[i][j] + " ");
            }
            System.out.println();
        }
    }
}
